﻿
using UnityEngine;
using UnityHFSM;
using moai_kun_v1;

public enum State 
{
    Start,
    Load,
    Running,
    Pause,
    Success,
    Failure,
    End,
}

public class GameSystem:MonoBehaviour
{
    public static GameSystem Instance;
    private void Awake()
    {
        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
            return;
        }
        Instance = this;
        DontDestroyOnLoad(gameObject);
        InitFSM();
    }
    private void Start()
    {
        InitGameFSM();
    }
    private void Update()
    {
        _gameFsm.OnLogic();
    }

    private void InitFSM()
    {
        _gameFsm = new StateMachine<State>();
        
    }
    private StateMachine<State> _gameFsm;
    private void InitGameFSM()
    {
        _gameFsm.AddState(State.Start, new StartState());
        _gameFsm.AddState(State.Load, new LoadState());
        _gameFsm.AddState(State.Running, new RunningState());
        _gameFsm.AddState(State.Pause, new PauseState());
        _gameFsm.AddState(State.Success, new SuccessState());
        _gameFsm.AddState(State.Failure, new FailureState());
        _gameFsm.AddState(State.End, new EndState());

        _gameFsm.SetStartState(State.Start);
        _gameFsm.Init();
    }

    public void ChangeGameState(State state) 
    {
        _gameFsm.RequestStateChange(state);
    }
    public int CurrentStageIndex
    {
        get => _stageIndex;
        set => _stageIndex = value;
    }
    public int ResetCount 
    {
        get => _resetCount;
        set => _resetCount = value;
    }

   
    private int _resetCount = 3;
    private int _stageIndex = 1;

    public MainPlayer CurrentPlayer;


}

